<template>
  <!-- 门店服务 -->
  <div class="outlet-service">
    <div class="search-bar">
      <el-form
        @submit.native.prevent
        :inline="true"
        class="search-form"
        ref="searchForm"
        :model="searchForm"
        size="small"
      >
        <div class="input-row">
          <el-form-item
            prop="name"
            :label="$t('outlet.tagName') + ':'"
            class="search-form-item"
          >
            <el-input
              v-model="searchForm.name"
              :placeholder="$t('outlet.tagName')"
            />
          </el-form-item>

          <el-form-item style="float: right">
            <div class="default-btn primary-btn" @click="searchChange(true)">
              {{ $t("product.search") }}
            </div>
            <div class="default-btn" @click="resetSearchForm('searchForm')">
              {{ $t("product.reset") }}
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="main-container">
      <div class="operation-bar">
        <div class="default-btn primary-btn" @click="addOrUpdateHandle()">
          {{ $t("crud.addTitle") }}
        </div>
      </div>
      <div class="table-con hot-search-table">
        <el-table
          ref="outletServiceListTable"
          :data="dataList"
          header-cell-class-name="table-header"
          row-class-name="table-row-low"
          style="width: 100%"
        >
          <el-table-column
            align="left"
            prop="name"
            :label="$t('outlet.tagName')"
            min-width="150"
          >
            <template slot-scope="scope">
              <span class="table-cell-text">{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            align="left"
            prop="categoryName"
            :label="$t('outlet.classification')"
             min-width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.categoryName" class="table-cell-text">{{ scope.row.categoryName }}</span>
              <span v-else class="table-cell-text">{{ $t('outlet.allClassify') }}</span>
            </template>
          </el-table-column> -->
          <!-- 状态 1.正常 0.下线 -1.删除 -->
          <!-- <el-table-column
            align="center"
            prop="recDate"
            :label="$t('outlet.status')"
            min-width="200"
            sortable>
            <template slot-scope="scope">
              <span v-if="scope.row.status===-1" class="table-cell-text">
                {{ $t('outlet.delete') }}
              </span>
              <span v-if="scope.row.status===0" class="table-cell-text">
                {{ $t('outlet.offline') }}
              </span>
              <span v-if="scope.row.status===1" class="table-cell-text">
                {{ $t('outlet.normal') }}
              </span>
            </template>
          </el-table-column> -->

          <el-table-column
            align="center"
            prop="createTime"
            :label="$t('weixin.createtime')"
            min-width="200"
            sortable
          >
          </el-table-column>

          <el-table-column
            fixed="right"
            align="center"
            :label="$t('publics.operating')"
            width="240"
          >
            <template slot-scope="scope">
              <div class="text-btn-con">
                <div
                  class="default-btn text-btn"
                  @click="addOrUpdateHandle(scope.row)"
                >
                  {{ $t("user.editBtn") }}
                </div>
                <div
                  class="default-btn text-btn"
                  @click.stop="deleteHandle(scope.row.id)"
                >
                  {{ $t("user.deleteBtn") }}
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="dataList.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      >
      </el-pagination>
    </div>
    <addOrUpdate
      v-if="addOrUpdateVisible"
      @refreshChange="refreshChange"
      ref="addOrUpdate"
    >
    </addOrUpdate>
  </div>
</template>

<script>
  import addOrUpdate from "./brand-tag-add-or-update.vue";
  export default {
    data() {
      return {
        dataList: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10, // 每页显示多少条
        },
        searchForm: {
          name: "",
        },
        addOrUpdateVisible: false,
      };
    },
    components: {
      addOrUpdate,
    },
    created() {},
    mounted() {
      this.getDataList();
    },
    methods: {
      getDataList(page) {
        this.dataListLoading = true;
        this.$http({
          url: this.$http.adornUrl("/platform/brandTag/page"),
          method: "get",
          params: this.$http.adornParams(
            Object.assign({
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize,
              ...this.searchForm,
            })
          ),
        }).then(({ data }) => {
          this.dataList = data.records;
          this.page.total = data.total;
          this.dataListLoading = false;
          // 末尾页数据为空重新请求
          if (!this.dataList.length && this.page.currentPage > 1) {
            this.page.currentPage = 1;
            this.getDataList();
          }
        });
      },
      // 点击查询
      searchChange(newData = false) {
        this.page.currentPage = 1;
        this.getDataList(this.page, newData);
      },
      resetSearchForm(formName) {
        this.$refs[formName].resetFields();
        this.searchForm = {};
      },
      // 新增 / 修改
      addOrUpdateHandle(item) {
        this.addOrUpdateVisible = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(item);
        });
      },
      deleteHandle(id) {
        this.$confirm(
          this.$i18n.t("outlet.doyouWantToDeleteTheTag"),
          this.$i18n.t("text.tips"),
          {
            confirmButtonText: this.$i18n.t("crud.filter.submitBtn"),
            cancelButtonText: this.$i18n.t("crud.cancelBtn"),
            type: "warning",
          }
        ).then(() => {
          this.$http({
            url: this.$http.adornUrl("/platform/brandTag/" + id),
            method: "delete",
            params: this.$http.adornParams(),
          }).then(() => {
            this.$message({
              message: this.$i18n.t("publics.operation"),
              type: "success",
            });
            this.getDataList();
          });
        });
      },
      // 刷新回调用
      refreshChange() {
        this.getDataList(this.page);
      },
      /**
       * 重置表单
       * @param {String} formName 表单名称
       */
      resetSearchForm(formName) {
        this.$refs[formName].resetFields();
        this.prodName = "";
        this.isTop = "";
        this.categoryId = null;
      },

      handleSizeChange(val) {
        this.page.pageSize = val;
        this.getDataList();
      },
      handleCurrentChange(val) {
        console.log(val);
        this.page.currentPage = val;
        this.getDataList();
      },
    },
  };
</script>
<style lang="scss" scoped></style>
